package jufdemo;

import java.text.DateFormat;
import java.util.Date;

import juf.Annotations.Name;
import juf.Annotations.Order;


/** Demo class
 * 
 * Using JUF we can build a UI on-the-fly for any arbitrary object like this.
 * JUF does not need to know anything about the object.
 * We can just create a JufInterface<T> (for a collection) or JufForm<T> (for an instance) of this type.
 * 
 * 
 * @author Dale Halliwell
 *
 */
public class Student implements Cloneable {
	//these are public fields, will be changeable by the user
	@Name("First Name:")
	public String firstname;
	@Name("Last Name:")
	public String lastname;
	@Name("Address:")
	public Address studentAddress;
	@Name("Date of birth:")
	public Date dob;
	
	private int studentID;
	
	public Student(String firstname, String lastname, Date dob){
		this.firstname = firstname;
		this.lastname = lastname;
		this.dob = dob;
		
		//generate a student id
		DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
		studentID = df.hashCode(); 
	}

	@Override
	public String toString(){		
		return this.firstname + " " + this.lastname;
	}

	//will be a readonly field, no setter
	@Order(1) //set the order of component
	@Name("Student ID:") //set the label
	public int getStudentID() {
		return studentID;
	}
	
	
    public Object clone() {
        try {
        	System.out.println("Cloned: " + this.toString());
            return super.clone();
        }
        catch (CloneNotSupportedException e) {
            throw new InternalError(e.toString());
        }
    }
	
	
}
